#ifndef __TASKQUEUE_H__
#define __TASKQUEUE_H__
#include <iostream>

#include <queue>
using std::queue;

#include <mutex>
using std::mutex;
using std::unique_lock;

#include <condition_variable>
using std::condition_variable;

#include <functional>
using std::function;

using ElemType = function<void()>;

class TaskQueue
{
public:
    TaskQueue(size_t capa);
    ~TaskQueue();
    void push(ElemType &&taskcb);
    ElemType pop();
    bool empty() const;
    bool full() const;
    void wakeup();//唤醒所有线程

private:
    size_t _capacity; //队列容量
    queue<ElemType> _que;  //存储数据的队列
    mutex _mutex;     //互斥锁
    condition_variable _notEmpty;//非空
    condition_variable _notFull; //非满
    bool _wakeFlag;//唤醒标志:当子线程睡眠时,跳出_notEmpty条件
};
#endif

